remove old_namespace and old_title from old table.
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 * @package MediaWiki
7 */
8
9 /**
10 * @todo document
11 * @package MediaWiki
12 */
13 class PageHistory {
14 var $mArticle, $mTitle, $mSkin;
15 var $lastline, $lastdate;
16 var $linesonpage;
17 function PageHistory( $article ) {
18 $this->mArticle =& $article;
19 $this->mTitle =& $article->mTitle;
20 }
21
22 # This shares a lot of issues (and code) with Recent Changes
23
24 function history() {
25 global $wgUser, $wgOut, $wgLang;
26
27 # If page hasn't changed, client can cache this
28
29 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
30 # Client cache fresh and headers sent, nothing more to do.
31 return;
32 }
33 $fname = 'PageHistory::history';
34 wfProfileIn( $fname );
35
36 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
37 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
38 $wgOut->setArticleFlag( false );
39 $wgOut->setArticleRelated( true );
40 $wgOut->setRobotpolicy( 'noindex,nofollow' );
41
42 if( $this->mTitle->getArticleID() == 0 ) {
43 $wgOut->addHTML( wfMsg( 'nohistory' ) );
44 wfProfileOut( $fname );
45 return;
46 }
47
48 list( $limit, $offset ) = wfCheckLimits();
49
50 /* We have to draw the latest revision from 'cur' */
51 $rawlimit = $limit;
52 $rawoffset = $offset - 1;
53 if( 0 == $offset ) {
54 $rawlimit--;
55 $rawoffset = 0;
56 }
57 /* Check one extra row to see whether we need to show 'next' and diff links */
58 $limitplus = $rawlimit + 1;
59
60 $namespace = $this->mTitle->getNamespace();
61 $title = $this->mTitle->getText();
62
63 $db =& wfGetDB( DB_SLAVE );
64 $use_index = $db->useIndexClause( 'articleid_timestamp' );
65 $oldtable = $db->tableName( 'old' );
66
67 $sql = "SELECT old_id,old_user," .
68 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
69 "FROM $oldtable $use_index " .
70 "WHERE old_articleid='" . $db->strencode( $this->mTitle->getArticleID() ) . "' " .
71 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
72 $res = $db->query( $sql, $fname );
73
74 $revs = $db->numRows( $res );
75
76 if( $revs < $limitplus ) // the sql above tries to fetch one extra
77 $this->linesonpage = $revs;
78 else
79 $this->linesonpage = $revs - 1;
80
81 $atend = ($revs < $limitplus);
82
83 $this->mSkin = $wgUser->getSkin();
84 $numbar = wfViewPrevNext(
85 $offset, $limit,
86 $this->mTitle->getPrefixedText(),
87 'action=history', $atend );
88 $s = $numbar;
89 if($this->linesonpage > 0) {
90 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
91 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
92 $this->submitbuttonhtml1 = $submitpart1 . ' />';
93 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
94 }
95 $s .= $this->beginHistoryList();
96 $counter = 1;
97 if( $offset == 0 ){
98 $this->linesonpage++;
99 $s .= $this->historyLine(
100 $this->mArticle->getTimestamp(),
101 $this->mArticle->getUser(),
102 $this->mArticle->getUserText(), $namespace,
103 $title, 0, $this->mArticle->getComment(),
104 ( $this->mArticle->getMinorEdit() > 0 ),
105 $counter++
106 );
107 }
108 while ( $line = $db->fetchObject( $res ) ) {
109 $s .= $this->historyLine(
110 $line->old_timestamp, $line->old_user,
111 $line->old_user_text, $namespace,
112 $title, $line->old_id,
113 $line->old_comment, ( $line->old_minor_edit > 0 ),
114 $counter++
115 );
116 }
117 $s .= $this->endHistoryList( !$atend );
118 $s .= $numbar;
119 $wgOut->addHTML( $s );
120 wfProfileOut( $fname );
121 }
122
123 function beginHistoryList() {
124 global $wgTitle;
125 $this->lastdate = $this->lastline = '';
126 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
127 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
128 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
129 $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
130 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
131 $s .= '<ul id="pagehistory">';
132 return $s;
133 }
134
135 function endHistoryList( $skip = false ) {
136 $last = wfMsg( 'last' );
137
138 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
139 $s .= '</ul>';
140 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2 : '';
141 $s .= '</form>';
142 return $s;
143 }
144
145 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
146 global $wgLang, $wgContLang;
147
148 $artname = Title::makeName( $ns, $ttl );
149 $last = wfMsg( 'last' );
150 $cur = wfMsg( 'cur' );
151 $cr = wfMsg( 'currentrev' );
152
153 if ( $oid && $this->lastline ) {
154 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
155 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
156 } else {
157 $ret = '';
158 }
159 $dt = $wgLang->timeanddate( $ts, true );
160
161 if ( $oid ) {
162 $q = 'oldid='.$oid;
163 } else {
164 $q = '';
165 }
166 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
167
168 if ( 0 == $u ) {
169 $ul = $this->mSkin->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
170 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
171 } else {
172 $ul = $this->mSkin->makeLink( $wgContLang->getNsText(
173 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
174 }
175
176 $s = '<li>';
177 if ( $oid ) {
178 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
179 'diff=0&oldid='.$oid );
180 } else {
181 $curlink = $cur;
182 }
183 $arbitrary = '';
184 if( $this->linesonpage > 1) {
185 # XXX: move title texts to javascript
186 $checkmark = '';
187 if ( !$oid ) {
188 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
189 $checkmark = ' checked="checked"';
190 } else {
191 if( $counter == 2 ) $checkmark = ' checked="checked"';
192 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
193 $checkmark = '';
194 }
195 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
196 }
197 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
198 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
199
200
201 if ( '' != $c && '*' != $c ) {
202 $c = $this->mSkin->formatcomment($c,$this->mTitle);
203 $s .= " <em>($c)</em>";
204 }
205 $s .= '</li>';
206
207 $this->lastline = $s;
208 return $ret;
209 }
210
211 }
212
213 ?>